# import pandas as pd
# import numpy as np
# import matplotlib.pyplot as plt
#
#
# plt.rcParams['font.sans-serif'].insert(0,'SimHei')#设置中文字体为SimHei
# plt.rcParams['axes.unicode_minus']=False#设置负号正常显示
#
# #读入数据
# # brand_file_path = '../../data/餐饮连锁数据.xlsx'  #相对路径
# # file_path = r'D:\code\Python\餐饮连锁店数据分析_实训\data\餐饮连锁数据.xlsx'
#
# # df = pd.read_excel(brand_file_path)
# # print(df.info)
# # print(df.head(3))
# # df.to_excel(brand_file_path,sheet_name='菜品信息',index=False)#含义：将df数据框写入brand_file_path文件的'菜品信息'工作表中，不包含索引列
# #读取'菜品信息'工作表
# # df_dish = pd.read_excel(brand_file_path,sheet_name='顾客评价')
# # print(df_dish.head(3))
# import pandas as pd
#
# # brand_file_path = r'../../data/餐饮连锁品牌数据.xlsx'  # 按你的实际路径修改
# #
# # # 1️⃣ 查看所有工作表名称
# # xls = pd.ExcelFile(brand_file_path)
# # print("【该文件包含以下工作表】：")
# # print(xls.sheet_names)
# #
# # import pandas as pd
# # import os
# #
# # brand_file_path = os.path.abspath('../../data/餐饮连锁数据.xlsx')
# # print("正在读取文件：", brand_file_path)
# #
# # xls = pd.read_excel(brand_file_path,sheet_name='品牌信息')
# # print("工作表列表：", xls.sheet_names)
# #
# # # 选择你需要的那个
# # sheet_name = xls.sheet_names[0]  # 或手动改为 '顾客评价'
# # df_dish = pd.read_excel(xls, sheet_name=sheet_name)
# # print(df_dish.head(3))
#
#
#
# # print(df.head(3))
#
# import pandas as pd
# import os
#
# # 修改为你的实际路径
# # brand_file_path = os.path.abspath('../../data/餐饮连锁数据.xlsx')
# brand_file_path = os.path.abspath('../../data/餐饮连锁数据.xlsx')
# print("正在读取文件：", brand_file_path)
# # 读取 Excel 文件结构
# xls = pd.ExcelFile(brand_file_path)
# print("📄 该文件包含以下工作表：")
# print(xls.sheet_names)
import numpy as np
import pandas as pd

brand_file_path = '../../data/raw data/餐饮连锁品牌数据.xlsx'
cater_file_path = '../../data/raw data/餐饮连锁数据.xlsx'
sheet_names=['门店信息','菜品信息','营销记录','顾客评价']
sheet_name=sheet_names[1]
df_dish = pd.read_excel(cater_file_path, sheet_name)
# # print(df_dish.head(3))
#
# file_path = cater_file_path  # 你上传的文件名
# df = pd.read_excel(file_path)

# print("【基本信息】")
# print(df_dish.info())
# print("\n【前5行数据预览】")
# print(df_dish.head())

# ======================================
# 2️⃣ 检查并处理空值
# ======================================
print("\n【空值统计】")
print(df_dish.isnull().sum())
print("======================")
# --- 测试1：查看哪些列空值最多 ---
missing_rate = df_dish.isnull().mean().sort_values(ascending=False)
print("\n【空值比例（Top 10）】")
print(missing_rate.head(10))
print("======================")
# --- 处理方式（可选） ---
# 填充数值列
num_cols = df_dish.select_dtypes(include=[np.number]).columns
for col in num_cols:
    df_dish[col].fillna(df_dish[col].mean(), inplace=True)

# 填充文本列
obj_cols = df_dish.select_dtypes(include=['object']).columns
for col in obj_cols:
    df_dish[col].fillna("未知", inplace=True)

# --- 验证：是否还有空值 ---
print("\n【空值处理后验证】")
print(df_dish.isnull().sum().sum())  # 0 表示处理完毕
print("===========================")